package org.kca.yarmour.data;

import org.kca.yarmour.yaquest.QuestInfoType;

public class Info
{
    private String type, value;
    private Integer amount;
    
    public Info()
    {
        this(null, null, 0);
    }
    
    public Info(String type, String value)
    {
        this(type, value, 0);
    }
    
    public Info(String type, String value, Integer amount)
    {
        this.type = type;
        this.value = value;
        this.amount = amount;
    }
    
    /**
     * Gets the type
     * @return the type
     */
    public String getType()
    {
        return type;
    }
    /**
     * Sets the type
     * @param type the type to set
     */
    public void setType(String type)
    {
        this.type = type;
    }
    /**
     * Gets the value
     * @return the value
     */
    public String getValue()
    {
        return value;
    }
    /**
     * Sets the value
     * @param value the value to set
     */
    public void setValue(String value)
    {
        this.value = value;
    }
    
    /**
     * Checks if the amount is specified
     * @return true if the amount is specified
     */
    public boolean isAmountSpecified()
    {
        return amount != null;
    }
    
    /**
     * Gets the amount
     * @return the amount
     */
    public int getAmount()
    {
        return amount;
    }
    
    /**
     * Gets the amount, or defaults to a specified amount if it is not specified
     * @param defamt the default amount if not specified
     * @return the amount 
     */
    public int getAmountSafely(int defamt)
    {
        if (amount == null)
        {
            return defamt;
        }
        else return amount;
    }
    
    /**
     * Sets the amount
     * @param amount the amount to set
     */
    public void setAmount(Integer amount)
    {
        this.amount = amount;
    }
    
    @Override
    public String toString()
    {
        return "(" + type + "," + value + "," + amount + ")";
    }
    
    /**
     * Creates an Info object from XML specifications
     * @param qinfo the quest info type
     * @return the Info object
     */
    public static Info createFromXmlType(QuestInfoType qinfo)
    {
        Info info = new Info(qinfo.getType(), qinfo.getValue(), qinfo.getQty());
        return info;
    }
}
